﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.world {
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;

    public class UpdateTreatmentCommand extends Command {

        public var event:UpdateTreatmentEvent;

        override public function execute():void{
            var _local2:RequestVO;
            var _local1:ITreatable = this.event.patient;
            this.event.params.id = _local1.currentTreatment.id;
            if (this.event.command == WorldConstants.FINALIZE){
                _local2 = new RequestVO(ProtocolConstants.LOAD_PATIENT, {id:this.assetPath}, true);
            };
            if (this.isFinishingLastTreatment){
                this.handleLastTreatment(_local1, _local2);
            } else {
                this.handleTreatment(_local2);
            };
        }
        private function handleTreatment(_arg1:RequestVO):void{
            var _local2:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST, this.onResult);
            _local2.addRequest(this.event.command, this.event.params);
            if (_arg1){
                _local2.addRequestVO(_arg1);
            };
            dispatch(_local2);
        }
        private function handleLastTreatment(_arg1:ITreatable, _arg2:RequestVO):void{
            var _local3:Array = [new RequestVO(this.event.command, this.event.params)];
            if (_arg2){
                _local3.push(_arg2);
            };
            var _local4:Object = {taskType:GameConstants.CURE_PET, itemType:_arg1.diseaseType, onResult:this.onResult};
            dispatch(new TaskRequestEvent(EventConstants.SEND_TASK_REQUEST, _local3, _local4));
        }
        private function get isFinishingLastTreatment():Boolean{
            return ((((this.event.command == WorldConstants.FINALIZE)) && (this.event.patient.isLastTreatment)));
        }
        private function get assetPath():String{
            var _local1:String = ((this.event.patient.type + "_") + this.event.patient.diseaseName);
            return (_local1.toLowerCase());
        }
        private function onResult(_arg1:ResultVO):void{
            var _local2:Function;
            if (_arg1.success){
                _local2 = this.event.callback;
                _local2(_arg1);
            };
        }

    }
}//package net.wooga.pets.controllers.world 
